﻿namespace REVISIONMAX20
{
    using MySql.Data.MySqlClient;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data.SQLite;
    using System.Drawing;
    using System.IO;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Windows.Forms;
    using WeifenLuo.WinFormsUI.Docking;

    public class frmGroup : DockContent
    {
        private UIHandler _uiHandler = null;
        private ToolStripButton btnApply;
        private ToolStripButton btnDelete;
        private ToolStripButton btnDumpDBsToBackup;
        private ToolStripButton btnExecute;
        private ToolStripButton btnReset;
        private ToolStripButton btnSave;
        private ToolStripButton btnUpdate;
        private IContainer components = null;
        private REVISIONMAX20.Group group = null;
        private Label label1;
        private Label label9;
        private MyConnectionStringList myConnectionStringList;
        private MyLogList myLogList;
        private MySourceList mySourceList;
        private MySQLItemList mySQLItemList;
        private Panel panel1;
        private TabPage tabConnectionStrings;
        private TabPage tabLogs;
        private TabControl tabMain;
        private TabPage tabSources;
        private TabPage tabSQLItems;
        private ToolStrip toolStrip1;
        private ToolStripSeparator toolStripSeparator1;
        private ToolStripSeparator toolStripSeparator2;
        private ToolStripSeparator toolStripSeparator3;
        private ToolStripSeparator toolStripSeparator4;
        private ToolStripSeparator toolStripSeparator5;
        private ToolStripSeparator toolStripSeparator6;
        private ToolStripSeparator toolStripSeparator7;
        private MyTextBox txtName;
        private MyTextBox txtRevision;

        public frmGroup()
        {
            this.InitializeComponent();
        }

        private void btnApply_Click(object sender, EventArgs e)
        {
            this.Save(true);
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("are you sure you want to delete this group?", "are you sure you want to delete this group?", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                List<int> idArray = new List<int>();
                idArray.Add(this.group.id);
                Common.DeleteGroups(idArray);
                this._uiHandler.groupPanel.UpdateViewer();
                base.Close();
            }
        }

        private void btnDumpDBsToBackup_Click(object sender, EventArgs e)
        {
            using (SQLiteConnection connection = Common.GetSQLiteConnection())
            {
                connection.Open();
                int num = 0;
                foreach (ConnectionString str in this.group.ConnectionStringList)
                {
                    if (!str.name.Equals("temp", StringComparison.CurrentCultureIgnoreCase))
                    {
                        StringBuilder builder2;
                        num++;
                        Log pErrorLog = new Log("", this.group, connection);
                        Log pOutLog = new Log("", this.group, connection);
                        MySqlConnectionStringBuilder connectionStringBuilder = str.ConnectionStringBuilder;
                        string path = AppDomain.CurrentDomain.BaseDirectory + @"backup\";
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }
                        string str3 = string.Format("{0}{1}_{2}_{3}.sql", new object[] { path, this.group.lastrevision, string.Format("{0:00}", num), connectionStringBuilder.Database });
                        if (File.Exists(str3))
                        {
                            File.Delete(str3);
                        }
                        string str4 = Common.DumpDB(connectionStringBuilder.UserID, connectionStringBuilder.Password, connectionStringBuilder.Database, str3, pErrorLog, pOutLog);
                        if (str4.Length > 0)
                        {
                            MessageBox.Show(str4.ToString());
                        }
                        if (!pErrorLog.value.IsEmpty())
                        {
                            builder2 = new StringBuilder();
                            builder2.AppendLine(string.Format("error executing: {0}", str3));
                            builder2.AppendLine("------------------------------------------------------------------");
                            builder2.AppendLine(pErrorLog.value);
                            builder2.AppendLine("------------------------------------------------------------------");
                            pErrorLog.value = builder2.ToString();
                            pErrorLog.SaveOrUpdate();
                        }
                        if (!pOutLog.value.IsEmpty())
                        {
                            builder2 = new StringBuilder();
                            builder2.AppendLine(string.Format("output executing: {0}", str3));
                            builder2.AppendLine("------------------------------------------------------------------");
                            builder2.AppendLine(pOutLog.value);
                            builder2.AppendLine("------------------------------------------------------------------");
                            pOutLog.value = builder2.ToString();
                            pOutLog.SaveOrUpdate();
                        }
                    }
                }
            }
        }

        private void btnExecute_Click(object sender, EventArgs e)
        {
            StringBuilder builder = new StringBuilder();
            List<SQLItem> sQLItemListForExecution = Common.GetSQLItemListForExecution(this.group);
            SortedList<int, string> connectionStringIdValueList = Common.GetConnectionStringIdValueList(this.group);
            try
            {
                foreach (SQLItem item in sQLItemListForExecution)
                {
                    if (connectionStringIdValueList.ContainsKey(item.connectionstringid))
                    {
                        string connectionString = connectionStringIdValueList[item.connectionstringid];
                        MySqlConnectionStringBuilder builder2 = new MySqlConnectionStringBuilder(connectionString);
                        using (SQLiteConnection connection = Common.GetSQLiteConnection())
                        {
                            string str2;
                            StringBuilder builder3;
                            connection.Open();
                            Log pErrorLog = new Log("", this.group, connection);
                            Log pOutLog = new Log("", this.group, connection);
                            if (item.sourcetype == "sqlfile")
                            {
                                str2 = Common.ExecuteBatch(builder2.UserID, builder2.Password, builder2.Database, item.source, pErrorLog, pOutLog);
                                if (!str2.IsEmpty())
                                {
                                    builder.AppendLine(str2);
                                }
                                if (builder.Length > 0)
                                {
                                    break;
                                }
                                item.executed = new DateTime?(DateTime.Now);
                                builder.Append(item.SaveOrUpdate().ToString());
                                if (builder.Length > 0)
                                {
                                    break;
                                }
                                this.group.lastrevision = item.revision;
                            }
                            else if (item.sourcetype == "sourcetext")
                            {
                                string tempFileName = Path.GetTempFileName();
                                File.WriteAllText(tempFileName, item.source);
                                str2 = Common.ExecuteBatch(builder2.UserID, builder2.Password, builder2.Database, tempFileName, pErrorLog, pOutLog);
                                File.Delete(tempFileName);
                                if (!str2.IsEmpty())
                                {
                                    builder.AppendLine(str2);
                                }
                                if (builder.Length > 0)
                                {
                                    break;
                                }
                                item.executed = new DateTime?(DateTime.Now);
                                builder.Append(item.SaveOrUpdate().ToString());
                                if (builder.Length > 0)
                                {
                                    break;
                                }
                                this.group.lastrevision = item.revision;
                            }
                            if (!pErrorLog.value.IsEmpty())
                            {
                                builder3 = new StringBuilder();
                                builder3.AppendLine(string.Format("error executing: {0}", item.source));
                                builder3.AppendLine("------------------------------------------------------------------");
                                builder3.AppendLine(pErrorLog.value);
                                builder3.AppendLine("------------------------------------------------------------------");
                                pErrorLog.value = builder3.ToString();
                                pErrorLog.SaveOrUpdate();
                            }
                            if (!pOutLog.value.IsEmpty())
                            {
                                builder3 = new StringBuilder();
                                builder3.AppendLine(string.Format("output executing: {0}", item.source));
                                builder3.AppendLine("------------------------------------------------------------------");
                                builder3.AppendLine(pOutLog.value);
                                builder3.AppendLine("------------------------------------------------------------------");
                                pOutLog.value = builder3.ToString();
                                pOutLog.SaveOrUpdate();
                            }
                        }
                    }
                }
                this.group.SaveOrUpdate();
            }
            catch (Exception exception)
            {
                builder.AppendLine(string.Format("Error: {0}", exception.Message));
            }
            if (builder.Length > 0)
            {
                MessageBox.Show(builder.ToString());
            }
            this.UpdateViewer();
        }

        private void btnReset_Click(object sender, EventArgs e)
        {
            StringBuilder builder = new StringBuilder();
            try
            {
                using (SQLiteConnection connection = Common.GetSQLiteConnection())
                {
                    connection.Open();
                    using (SQLiteCommand command = connection.CreateCommand())
                    {
                        command.CommandText = string.Format("update sqlitems set `executed` = null where parentid = {0} ", this.group.id);
                        command.ExecuteNonQuery();
                    }
                }
                this.group.lastrevision = 0;
                this.group.SaveOrUpdate();
            }
            catch (Exception exception)
            {
                builder.AppendLine(string.Format("Error: {0}", exception.Message));
            }
            if (builder.Length > 0)
            {
                MessageBox.Show(builder.ToString());
            }
            this.UpdateViewer();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            this.Save(false);
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            StringBuilder errors = new StringBuilder();
            try
            {
                using (SQLiteConnection connection = Common.GetSQLiteConnection())
                {
                    connection.Open();
                    using (SQLiteTransaction transaction = connection.BeginTransaction())
                    {
                        using (SQLiteCommand command = connection.CreateSQLItemCommand())
                        {
                            List<Source> sourceList = Common.GetSourceList(this.group);
                            SortedList<string, int> connectionStringNameIdList = Common.GetConnectionStringNameIdList(this.group);
                            SortedList<string, SQLItem> sQLItemSQLFileList = Common.GetSQLItemSQLFileList(this.group);
                            foreach (Source source in sourceList)
                            {
                                string[] strArray = Directory.GetFiles(source.source, "*.sql", source.recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
                                foreach (string str in strArray)
                                {
                                    if (!sQLItemSQLFileList.ContainsKey(str))
                                    {
                                        string str4;
                                        string[] strArray2;
                                        SQLItem item = new SQLItem(str, "sqlfile", this.group, connection);
                                        string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(str);
                                        string pattern = "[0-9]+_[0-9]+_[a-zA-Z0-9]+_.*";
                                        if (Regex.IsMatch(fileNameWithoutExtension, pattern))
                                        {
                                            str4 = "([0-9]+)_([0-9]+)_([a-zA-Z0-9]+)_(.*)";
                                            strArray2 = Regex.Replace(fileNameWithoutExtension, str4, "$1\t$2\t$3\t$4").Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
                                            item.connectionstringid = connectionStringNameIdList[strArray2[2]];
                                            item.revision = strArray2[0].IntValueOrZero();
                                            item.index = strArray2[1].IntValueOrZero();
                                        }
                                        else
                                        {
                                            pattern = "[0-9]+_[0-9]+_[a-zA-Z0-9]";
                                            if (Regex.IsMatch(fileNameWithoutExtension, pattern))
                                            {
                                                str4 = "([0-9]+)_([0-9]+)_([a-zA-Z0-9]+)";
                                                strArray2 = Regex.Replace(fileNameWithoutExtension, str4, "$1\t$2\t$3").Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
                                                item.connectionstringid = connectionStringNameIdList[strArray2[2]];
                                                item.revision = strArray2[0].IntValueOrZero();
                                                item.index = strArray2[1].IntValueOrZero();
                                            }
                                        }
                                        item.SaveOrUpdate(command, errors);
                                    }
                                }
                            }
                            transaction.Commit();
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                errors.AppendLine(string.Format("Error: {0}", exception.Message));
            }
            if (errors.Length > 0)
            {
                MessageBox.Show(errors.ToString());
            }
            this.UpdateViewer();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.toolStrip1 = new System.Windows.Forms.ToolStrip();
            this.btnSave = new System.Windows.Forms.ToolStripButton();
            this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
            this.btnApply = new System.Windows.Forms.ToolStripButton();
            this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
            this.btnDelete = new System.Windows.Forms.ToolStripButton();
            this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
            this.btnUpdate = new System.Windows.Forms.ToolStripButton();
            this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
            this.btnExecute = new System.Windows.Forms.ToolStripButton();
            this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator();
            this.btnReset = new System.Windows.Forms.ToolStripButton();
            this.toolStripSeparator6 = new System.Windows.Forms.ToolStripSeparator();
            this.btnDumpDBsToBackup = new System.Windows.Forms.ToolStripButton();
            this.toolStripSeparator7 = new System.Windows.Forms.ToolStripSeparator();
            this.panel1 = new System.Windows.Forms.Panel();
            this.label1 = new System.Windows.Forms.Label();
            this.label9 = new System.Windows.Forms.Label();
            this.txtRevision = new REVISIONMAX20.MyTextBox(this.components);
            this.txtName = new REVISIONMAX20.MyTextBox(this.components);
            this.tabMain = new System.Windows.Forms.TabControl();
            this.tabSQLItems = new System.Windows.Forms.TabPage();
            this.mySQLItemList = new REVISIONMAX20.MySQLItemList();
            this.tabSources = new System.Windows.Forms.TabPage();
            this.mySourceList = new REVISIONMAX20.MySourceList();
            this.tabLogs = new System.Windows.Forms.TabPage();
            this.myLogList = new REVISIONMAX20.MyLogList();
            this.tabConnectionStrings = new System.Windows.Forms.TabPage();
            this.myConnectionStringList = new REVISIONMAX20.MyConnectionStringList();
            this.toolStrip1.SuspendLayout();
            this.panel1.SuspendLayout();
            this.tabMain.SuspendLayout();
            this.tabSQLItems.SuspendLayout();
            this.tabSources.SuspendLayout();
            this.tabLogs.SuspendLayout();
            this.tabConnectionStrings.SuspendLayout();
            this.SuspendLayout();
            // 
            // toolStrip1
            // 
            this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.btnSave,
            this.toolStripSeparator1,
            this.btnApply,
            this.toolStripSeparator2,
            this.btnDelete,
            this.toolStripSeparator3,
            this.btnUpdate,
            this.toolStripSeparator4,
            this.btnExecute,
            this.toolStripSeparator5,
            this.btnReset,
            this.toolStripSeparator6,
            this.btnDumpDBsToBackup,
            this.toolStripSeparator7});
            this.toolStrip1.Location = new System.Drawing.Point(0, 0);
            this.toolStrip1.Name = "toolStrip1";
            this.toolStrip1.Size = new System.Drawing.Size(679, 25);
            this.toolStrip1.TabIndex = 7;
            this.toolStrip1.Text = "toolStrip1";
            // 
            // btnSave
            // 
            this.btnSave.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
            this.btnSave.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnSave.Name = "btnSave";
            this.btnSave.Size = new System.Drawing.Size(35, 22);
            this.btnSave.Text = "Save";
            this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
            // 
            // toolStripSeparator1
            // 
            this.toolStripSeparator1.Name = "toolStripSeparator1";
            this.toolStripSeparator1.Size = new System.Drawing.Size(6, 25);
            // 
            // btnApply
            // 
            this.btnApply.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
            this.btnApply.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnApply.Name = "btnApply";
            this.btnApply.Size = new System.Drawing.Size(38, 22);
            this.btnApply.Text = "Apply";
            this.btnApply.Click += new System.EventHandler(this.btnApply_Click);
            // 
            // toolStripSeparator2
            // 
            this.toolStripSeparator2.Name = "toolStripSeparator2";
            this.toolStripSeparator2.Size = new System.Drawing.Size(6, 25);
            // 
            // btnDelete
            // 
            this.btnDelete.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
            this.btnDelete.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnDelete.Name = "btnDelete";
            this.btnDelete.Size = new System.Drawing.Size(42, 22);
            this.btnDelete.Text = "Delete";
            this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
            // 
            // toolStripSeparator3
            // 
            this.toolStripSeparator3.Name = "toolStripSeparator3";
            this.toolStripSeparator3.Size = new System.Drawing.Size(6, 25);
            // 
            // btnUpdate
            // 
            this.btnUpdate.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
            this.btnUpdate.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnUpdate.Name = "btnUpdate";
            this.btnUpdate.Size = new System.Drawing.Size(46, 22);
            this.btnUpdate.Text = "Update";
            this.btnUpdate.Click += new System.EventHandler(this.btnUpdate_Click);
            // 
            // toolStripSeparator4
            // 
            this.toolStripSeparator4.Name = "toolStripSeparator4";
            this.toolStripSeparator4.Size = new System.Drawing.Size(6, 25);
            // 
            // btnExecute
            // 
            this.btnExecute.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
            this.btnExecute.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnExecute.Name = "btnExecute";
            this.btnExecute.Size = new System.Drawing.Size(50, 22);
            this.btnExecute.Text = "Execute";
            this.btnExecute.Click += new System.EventHandler(this.btnExecute_Click);
            // 
            // toolStripSeparator5
            // 
            this.toolStripSeparator5.Name = "toolStripSeparator5";
            this.toolStripSeparator5.Size = new System.Drawing.Size(6, 25);
            // 
            // btnReset
            // 
            this.btnReset.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
            this.btnReset.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnReset.Name = "btnReset";
            this.btnReset.Size = new System.Drawing.Size(39, 22);
            this.btnReset.Text = "Reset";
            this.btnReset.Click += new System.EventHandler(this.btnReset_Click);
            // 
            // toolStripSeparator6
            // 
            this.toolStripSeparator6.Name = "toolStripSeparator6";
            this.toolStripSeparator6.Size = new System.Drawing.Size(6, 25);
            // 
            // btnDumpDBsToBackup
            // 
            this.btnDumpDBsToBackup.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
            this.btnDumpDBsToBackup.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnDumpDBsToBackup.Name = "btnDumpDBsToBackup";
            this.btnDumpDBsToBackup.Size = new System.Drawing.Size(116, 22);
            this.btnDumpDBsToBackup.Text = "Dump DB\'s To Backup ";
            this.btnDumpDBsToBackup.Click += new System.EventHandler(this.btnDumpDBsToBackup_Click);
            // 
            // toolStripSeparator7
            // 
            this.toolStripSeparator7.Name = "toolStripSeparator7";
            this.toolStripSeparator7.Size = new System.Drawing.Size(6, 25);
            // 
            // panel1
            // 
            this.panel1.Controls.Add(this.label1);
            this.panel1.Controls.Add(this.label9);
            this.panel1.Controls.Add(this.txtRevision);
            this.panel1.Controls.Add(this.txtName);
            this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
            this.panel1.Location = new System.Drawing.Point(0, 25);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(679, 31);
            this.panel1.TabIndex = 8;
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(213, 1);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(52, 20);
            this.label1.TabIndex = 10;
            this.label1.Text = "Revision";
            // 
            // label9
            // 
            this.label9.Location = new System.Drawing.Point(2, 3);
            this.label9.Name = "label9";
            this.label9.Size = new System.Drawing.Size(36, 20);
            this.label9.TabIndex = 10;
            this.label9.Text = "Name";
            // 
            // txtRevision
            // 
            this.txtRevision.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.txtRevision.ForeColor = System.Drawing.Color.Blue;
            this.txtRevision.Location = new System.Drawing.Point(271, 1);
            this.txtRevision.Name = "txtRevision";
            this.txtRevision.Size = new System.Drawing.Size(83, 20);
            this.txtRevision.TabIndex = 1;
            this.txtRevision.TextChanged += new System.EventHandler(this.txtRevision_TextChanged);
            // 
            // txtName
            // 
            this.txtName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.txtName.ForeColor = System.Drawing.Color.Blue;
            this.txtName.Location = new System.Drawing.Point(44, 1);
            this.txtName.Name = "txtName";
            this.txtName.Size = new System.Drawing.Size(163, 20);
            this.txtName.TabIndex = 0;
            this.txtName.TextChanged += new System.EventHandler(this.txtName_TextChanged);
            // 
            // tabMain
            // 
            this.tabMain.Controls.Add(this.tabSQLItems);
            this.tabMain.Controls.Add(this.tabSources);
            this.tabMain.Controls.Add(this.tabLogs);
            this.tabMain.Controls.Add(this.tabConnectionStrings);
            this.tabMain.Dock = System.Windows.Forms.DockStyle.Fill;
            this.tabMain.Location = new System.Drawing.Point(0, 56);
            this.tabMain.Name = "tabMain";
            this.tabMain.SelectedIndex = 0;
            this.tabMain.Size = new System.Drawing.Size(679, 232);
            this.tabMain.TabIndex = 9;
            this.tabMain.TabIndexChanged += new System.EventHandler(this.tabMain_TabIndexChanged);
            // 
            // tabSQLItems
            // 
            this.tabSQLItems.Controls.Add(this.mySQLItemList);
            this.tabSQLItems.Location = new System.Drawing.Point(4, 22);
            this.tabSQLItems.Name = "tabSQLItems";
            this.tabSQLItems.Padding = new System.Windows.Forms.Padding(3);
            this.tabSQLItems.Size = new System.Drawing.Size(671, 206);
            this.tabSQLItems.TabIndex = 0;
            this.tabSQLItems.Text = "SQLItems";
            this.tabSQLItems.UseVisualStyleBackColor = true;
            // 
            // mySQLItemList
            // 
            this.mySQLItemList.Dock = System.Windows.Forms.DockStyle.Fill;
            this.mySQLItemList.Location = new System.Drawing.Point(3, 3);
            this.mySQLItemList.Name = "mySQLItemList";
            this.mySQLItemList.Size = new System.Drawing.Size(665, 200);
            this.mySQLItemList.TabIndex = 0;
            this.mySQLItemList.uiHandler = null;
            // 
            // tabSources
            // 
            this.tabSources.Controls.Add(this.mySourceList);
            this.tabSources.Location = new System.Drawing.Point(4, 22);
            this.tabSources.Name = "tabSources";
            this.tabSources.Padding = new System.Windows.Forms.Padding(3);
            this.tabSources.Size = new System.Drawing.Size(667, 199);
            this.tabSources.TabIndex = 1;
            this.tabSources.Text = "Sources";
            this.tabSources.UseVisualStyleBackColor = true;
            // 
            // mySourceList
            // 
            this.mySourceList.Dock = System.Windows.Forms.DockStyle.Fill;
            this.mySourceList.Location = new System.Drawing.Point(3, 3);
            this.mySourceList.Name = "mySourceList";
            this.mySourceList.Size = new System.Drawing.Size(661, 193);
            this.mySourceList.TabIndex = 0;
            this.mySourceList.uiHandler = null;
            // 
            // tabLogs
            // 
            this.tabLogs.Controls.Add(this.myLogList);
            this.tabLogs.Location = new System.Drawing.Point(4, 22);
            this.tabLogs.Name = "tabLogs";
            this.tabLogs.Size = new System.Drawing.Size(667, 199);
            this.tabLogs.TabIndex = 2;
            this.tabLogs.Text = "Logs";
            this.tabLogs.UseVisualStyleBackColor = true;
            // 
            // myLogList
            // 
            this.myLogList.Dock = System.Windows.Forms.DockStyle.Fill;
            this.myLogList.Location = new System.Drawing.Point(0, 0);
            this.myLogList.Name = "myLogList";
            this.myLogList.Size = new System.Drawing.Size(667, 199);
            this.myLogList.TabIndex = 0;
            this.myLogList.uiHandler = null;
            // 
            // tabConnectionStrings
            // 
            this.tabConnectionStrings.Controls.Add(this.myConnectionStringList);
            this.tabConnectionStrings.Location = new System.Drawing.Point(4, 22);
            this.tabConnectionStrings.Name = "tabConnectionStrings";
            this.tabConnectionStrings.Padding = new System.Windows.Forms.Padding(3);
            this.tabConnectionStrings.Size = new System.Drawing.Size(667, 199);
            this.tabConnectionStrings.TabIndex = 3;
            this.tabConnectionStrings.Text = "Connection Strings";
            this.tabConnectionStrings.UseVisualStyleBackColor = true;
            // 
            // myConnectionStringList
            // 
            this.myConnectionStringList.Dock = System.Windows.Forms.DockStyle.Fill;
            this.myConnectionStringList.Location = new System.Drawing.Point(3, 3);
            this.myConnectionStringList.Name = "myConnectionStringList";
            this.myConnectionStringList.Size = new System.Drawing.Size(661, 193);
            this.myConnectionStringList.TabIndex = 0;
            this.myConnectionStringList.uiHandler = null;
            // 
            // frmGroup
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(679, 288);
            this.Controls.Add(this.tabMain);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.toolStrip1);
            this.Name = "frmGroup";
            this.toolStrip1.ResumeLayout(false);
            this.toolStrip1.PerformLayout();
            this.panel1.ResumeLayout(false);
            this.panel1.PerformLayout();
            this.tabMain.ResumeLayout(false);
            this.tabSQLItems.ResumeLayout(false);
            this.tabSources.ResumeLayout(false);
            this.tabLogs.ResumeLayout(false);
            this.tabConnectionStrings.ResumeLayout(false);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        private void Save(bool apply)
        {
            this.UpdateObject();
            StringBuilder builder = this.group.SaveOrUpdate();
            if (builder.Length > 0)
            {
                MessageBox.Show(builder.ToString());
            }
            else
            {
                this._uiHandler.groupPanel.UpdateViewer();
                if (!apply)
                {
                    base.Close();
                }
            }
        }

        private void tabMain_TabIndexChanged(object sender, EventArgs e)
        {
            if (this.tabMain.SelectedTab == this.tabSQLItems)
            {
                this.mySQLItemList.UpdateViewer();
            }
            else if (this.tabMain.SelectedTab == this.tabSources)
            {
                this.mySourceList.UpdateViewer();
            }
            else if (this.tabMain.SelectedTab == this.tabLogs)
            {
                this.myLogList.UpdateViewer();
            }
            else if (this.tabMain.SelectedTab == this.tabSQLItems)
            {
                this.myConnectionStringList.UpdateViewer();
            }
        }

        private void txtName_TextChanged(object sender, EventArgs e)
        {
            this.Text = "Group: " + this.txtName.Text + " " + this.txtRevision.Text;
        }

        private void txtRevision_TextChanged(object sender, EventArgs e)
        {
            this.Text = "Group: " + this.txtName.Text + " " + this.txtRevision.Text;
        }

        private void UpdateObject()
        {
            this.group.name = this.txtName.Text;
            this.group.lastrevision = this.txtRevision.Text.IntValueOrZero();
        }

        private void UpdateViewer()
        {
            this.txtName.Text = this.group.name;
            this.txtRevision.Text = this.group.lastrevision.StringValueOrEmpty();
            this.mySQLItemList.Initzialize(this._uiHandler, this.group);
            this.mySourceList.Initzialize(this._uiHandler, this.group);
            this.myLogList.Initzialize(this._uiHandler, this.group);
            this.myConnectionStringList.Initzialize(this._uiHandler, this.group);
        }

        public void View(UIHandler puiHandler, REVISIONMAX20.Group pGroup)
        {
            this._uiHandler = puiHandler;
            this.group = pGroup;
            this.UpdateViewer();
        }

        public int id
        {
            get
            {
                return this.group.id;
            }
        }
    }
}

